<!-- 登录 -->
<template>
  <div class="loginCnt">
    <div class="box">
      <div class="img">
        <img :src="require('@/assets/images/login/login_bg.svg')" alt="" />
      </div>

      <div class="line"></div>

      <div
        class="inputBox"
        v-loading="loading"
        element-loading-text="拼命加载中"
        element-loading-background="rgba(226, 229, 234, 0.23)"
      >
        <h3>高校实验室安全监管系统</h3>
        <h4 class="cr-hui3 mt-50 fs-22 ml-20">Hi ,</h4>
        <h4 class="cr-hui3 fs-22 ml-20 mb-40">欢迎回来，请先登录吧</h4>
        <div class="input">
          <el-input
            v-model="account"
            placeholder="请输入用户名"
            width="320px"
            autofocus
            prefix-icon="el-icon-user-solid"
            style="margin-bottom: 24px"
          >
          </el-input>
          <el-input
            v-model="password"
            placeholder="请输入密码"
            prefix-icon="el-icon-unlock"
            @keyup.enter.native="doLogin"
            show-password
          ></el-input>
          <p class="loginBtn" @click="doLogin">登录</p>
        </div>
      </div>
    </div>
    <div class="footer">Copyright © 2019 安志生态</div>
  </div>
</template>
<script>
import {
  getLogin,
  findLaboratoryByCollegeNo,
  colleges,
  laboratory,
  department,
  userInfo,
  findFloorByUser,
} from "@/http/api";
import { mapActions, mapMutations } from "vuex";
import { fullScreen, exitScreen, isFullScreen } from "@/utils/common";
export default {
  name: "login",
  data() {
    return {
      msg: "hello login!",
      loading: false,
      account: "",
      password: "",
    };
  },
  mounted() {
    let once = sessionStorage.getItem("once");
    if (!once) {
      this.open();
    }
  },
  methods: {
    ...mapMutations("user", ["updateUserToken"]),
    ...mapMutations("laboratory", ["setLaboratoryByColleg"]),
    /* 是否为全屏 */
    open() {
      sessionStorage.setItem("once", true);
      this.$confirm(
        "<p style='color: #21333f'>" +
          "是否切换至全屏?</p>" +
          "<p style='color: #b5c4d0'>(全屏状态下平台体验效果会更好) </p>",
        "提示信息",

        {
          dangerouslyUseHTMLString: true,
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "info",
        }
      )
        .then(() => {
          document.documentElement.requestFullscreen();
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    //登陆请求
    async doLogin() {
      this.loading = true;
      let result = await getLogin({
        nickName: this.account,
        password: this.password,
      });
      if (result.code === 20000) {
        localStorage.setItem("token", result.data);
        let laboratoryByCollege = await findLaboratoryByCollegeNo();
        let userInfoDetail = await userInfo();
        let collegesData = await colleges();
        let laboratoryData = await laboratory();
        let departmentData = await department();
        let findFloorByUserData = await findFloorByUser();
        localStorage.setItem("userInfo", JSON.stringify(userInfoDetail.data));
        localStorage.setItem("collegesData", JSON.stringify(collegesData.data));
        localStorage.setItem(
          "findFloorByUserData",
          JSON.stringify(findFloorByUserData.data)
        );
        localStorage.setItem(
          "laboratoryData",
          JSON.stringify(laboratoryData.data)
        );
        localStorage.setItem(
          "departmentData",
          JSON.stringify(departmentData.data)
        );
        localStorage.setItem(
          "laboratoryByCollege",
          JSON.stringify(laboratoryByCollege.data)
        );
        this.$notify({
          title: "成功",
          message: "登录成功！",
          type: "success",
        });
        this.$router.push({
          name: "home",
        });
        this.updateUserToken(result.data);
      }
    },
  },
};
</script>
<style scoped>
.loginCnt {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  background-color: #ffffff;
  overflow: hidden;
}

.box {
  position: relative;
  top: 45%;
  display: flex;
  align-items: center;
  height: 474px;
  margin: 0 auto;
  margin-top: -237px;
  transition: 0.3s ease-in-out;
  z-index: 1;
  padding-left: 12%;
}

.box .img {
  position: absolute;
  bottom: 0px;
  /* top: 240px; */
  top: 60%;
  transform: translateY(-50%);
  left: 13%;
  height: 704px;
  width: 998px;
}

.box .img img {
  height: 100%;
}

.box .line {
  position: absolute;
  top: 20%;
  width: 1px;
  height: 74%;
  background-color: #fff;
  left: 50%;
}

.box .inputBox {
  position: absolute;
  box-sizing: border-box;
  width: 420px;
  right: 10%;
  padding: 5% 30px;
}

.box .inputBox::after {
  content: "";
  background: red;
}

.box .inputBox h3 {
  letter-spacing: 2px;
  color: #00bfb1;
  font-weight: bold;
  text-align: center;
  font-weight: 600;
  font-size: 30px;
  margin-bottom: 30px;
  line-height: 42px;
}

.inputBox .loginBtn {
  text-align: center;
  margin-top: 60px;
  width: 100%;
  line-height: 44px;
  height: 40px;
  border-radius: 27px;
  color: #ffffff;
  box-shadow: 0px 5px 15px 0px rgba(78, 78, 78, 0.4);
  cursor: pointer;
  transition: background-color 0.3s ease-in-out;
  background: #00bfb1;
}

.inputBox .loginBtn:hover {
  background-color: #00bfb1;
  color: #fff;
}

.inputBox .footerBtn {
  width: 100%;
  height: 26px;
  line-height: 26px;
  margin: 20px 0 12px 0;
  display: flex;
  justify-content: space-between;
}

.inputBox .footerBtn .forgetPassword {
  text-decoration: underline;
  color: #fff;
  cursor: pointer;
  float: right;
}

.inputBox .input {
  width: 90%;
  margin: 0 auto;
}

@media (min-width: 1600px) {
  .box {
    padding-left: 0;
  }

  .box .line {
    left: 49%;
  }

  .box .inputBox {
    width: 420px;
    /* right: 0; */
    padding: 6% 30px;
  }
}

.box .tips {
  width: 100%;
  text-align: center;
  position: absolute;
  line-height: 26px;
  background: #3f3d56;
  top: -26px;
  left: 0;
  color: #fff;
  border-radius: 4px 4px 0 0;
}

.box .tips a {
  color: #fff;
  text-decoration: underline;
}

.experience .line {
  text-align: center;
}

.experience {
  margin-top: 20px;
}

.experience .subTit {
  font-size: 18px;
  color: #444;
  line-height: 44px;
  margin-bottom: 15px;
}

.footer {
  position: absolute;
  width: 100%;
  bottom: 0;
  text-align: center;
  color: #eee;
  font-size: 12px;
}
</style>
<style scoped>
.input /deep/.el-input__inner {
  width: 319px;
  height: 42px;
  background: #e9f2f2 !important;
  border-radius: 21px;
}
.input /deep/ .el-input--prefix .el-input__inner {
  padding-left: 60px;
}
.input /deep/.el-icon-user-solid {
  top: 9px;
  left: 20px;
  font-size: 20px;
  width: 30px;
  height: 30px;
  margin-right: 10px;
  position: relative;
  color: #00bfb1;
}
.input /deep/ .el-icon-unlock {
  top: 9px;
  left: 20px;
  font-size: 20px;
  width: 30px;
  height: 30px;
  margin-right: 10px;
  position: relative;
  color: #00bfb1;
}
.input /deep/ .el-input .el-input__clear {
  position: relative;
  right: 11px;
  top: 4px;
}
</style>
